/*
* Copyright (c) 2010 The Turing Project
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* Except as contained in this notice, the name(s) of the above
* copyright holders shall not be used in advertising or otherwise to
* promote the sale, use or other dealings in this Software without prior
* written authorization.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
 */

package userinterface;

import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.JFrame;
import simulator.Model;

public class GUI extends JFrame implements ActionListener, ChangeListener {
    //ProjectionBox _camera = new ProjectionBox();
    Model _model = new Model();
    ProjectionBox _box = new ProjectionBox();
    ProjectionPanel _projection = new ProjectionPanel();

    private Double _lastFrameTime = 0.0;
    private Double _frameTimeStep = 0.0;


    /**
     * The GUI class constructor accepts a Model object that will
     * be displayed and manipulted by the graphic user interface.
     * @param model
     */
    public GUI(Model model) {
        super();
        _model = model;
        _box.reframeModel(model);
        setSize(800,800);
        setTitle("The Turing Project");

        _lastFrameTime = 0.0;
        _frameTimeStep = 0.2;
        // Activate listeners
        //play.addActionListener(this);
        _projection.setProjection(_box, _model);

        // Add pannels to the window
        add(_projection);

        

        // Respond to close comand
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        // Make window visible
        setVisible(true);

        for(int i=0; i < 10000000; i++) {
            for(int j=0;j<10;j++){
              _model.advanceTime();
              if (_model.getTime() - _lastFrameTime > _model.getMaximumTimeIncrement()) {
                  _projection.repaint();
                  _lastFrameTime = _model.getTime();
              }
            }
//            _projection.repaint();
   
        }
    }

    


    public void stateChanged(ChangeEvent event) {


    }

   public void actionPerformed(ActionEvent event) {
       String command = event.getActionCommand();

       if (command.equals("Play")) {
            String greeting = "You pressed play!";
            System.out.println(greeting);

       }
    }
 }

